<template>
  <div class="tabBar">
    <div v-for="(el,index) in tabBarNames" :key="index" @click="switchBar(index,el)" class="tabBar_list">
      <div class="itemView">
        <div style="position: relative">
          <p class="itemLabel"
             :style="index == selectedIndex ? 'color: #005BAB;' : 'color: #333333;'">
            {{el.name}}</p>
          <div v-if="index == selectedIndex" class="selectedLine"></div>
        </div>

        <div v-if="index != tabBarNames.length - 1" class="lineView"></div>
      </div>
    </div>
  </div>
</template>

<script>

  export default {
    props: {
      selectedIndex: {
        type: Number,
        default: 0,
        required: true
      },
      tabBarNames: {
        type: null,
        required: true
      }
    },
    methods: {
      switchBar (index,el) {
        this.$emit('tabBarChange', index,el)
      }
    },
  }
</script>

<style scoped>
  .tabBar {
    box-sizing: border-box;
    padding-left: 20px;
    display: flex;
    justify-content: flex-start;
    border-bottom: #E7E7E7 solid 1px;
    width: 100%;
    height: 44px;
    overflow-y: hidden;
    overflow-x: scroll;
    white-space: nowrap;
    background-color: white;
  }
  .tabBar::-webkit-scrollbar {
    display: none;
  }
  .tabBar_list:last-child {
    padding-right: 32px;
  }
  .itemView {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    height: 44px;
  }

  .itemLabel {
    line-height: 44px;
    font-weight: bold;
    font-size: 15px;
    color: #333333;
  }
  .selectedLine {
    position: absolute;
    bottom: 1px;
    left: 0;
    right: 0;
    background-color: #005BAB;
    height: 4px;
    border-radius: 2px;
  }
  .lineView {
    background: #E7E7E7;
    width: 1px;
    height: 16px;
    margin: 0 26px;
  }


</style>
